Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feature: add pubsub (tests and API Spec) #101

Merged
merged 9 commits into from
Dec 21, 2016
Merged

feature: add pubsub (tests and API Spec) #101

merged 9 commits into from
Dec 21, 2016

Conversation

haadcode
Copy link
Contributor

@haadcode haadcode commented Dec 5, 2016

This PR will add tests for the upcoming pubsub API.

Note that this PR is dependent on ipfs-inactive/js-ipfs-http-client#465.


const expect = require('chai').expect
const isNode = require('detect-node')
const PubsubMessage = require('../../src/pubsub-message') // eslint-disable-line no-unused-vars
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include this if we don't need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need it eventually. Leaving it there as a placeholder.

However, these should not be required from '../src' but from ipfs-api. @dignifiedquire how can I do that? interface-ipfs-api tests that refer to components in js-ipfs-api (and the same components will prolly be used in js-ipfs) but are not publicly exposed by the module?

Copy link
Contributor

@dignifiedquire dignifiedquire Dec 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't require them, they should be passed in through the setup function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How? How passed what? Can you provide an example?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests have a before filter, which calls common.setup, so you can pass more things through there. You could either add the functionality to the factory or as a third parameter.

describe('immutable properties', () => {
const message = PubsubMessageUtils.create('A', 'hello', '123', ['hello world'])

it('from', () => {
Copy link
Contributor

@victorb victorb Dec 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this doesn't throw any exception, won't the test pass?

Should be something like this instead:

let err = null
try {
  message.from = 'not allowed'
} catch (e) {
  err = e
}
expect(e).to.be.an('error')
expect(e.toString()).to.equal(`TypeError: Cannot set property from of #<PubsubMessage> which has only a getter`)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Will fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that's the right fix. You just added a expect in the try part, which would not get run if there is an error and now we're doing different assertions depending on if the code throws an exception or not. The tests should not be able to change the executed code path.

Copy link
Contributor Author

@haadcode haadcode Dec 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, all this got me thinking.

I changed it a bit and just pushed a new commit to make it even more implicit that we're testing immutability here: check that the values are the same as before if no error is thrown.

loop()
})

it('call subscribe 1k times', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implicitly tested in the subscribe/unsubscribe 1k times, so we can remove this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsubscribe changes the internal state. This test is meant to make sure that NOT calling unsubscribe before calling subscribe again doesn't change the state and works as expected.

})
})

it('call publish 1k times', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implicitly tested in the subscribe/unsubscribe 1k times, so we can remove this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@haadcode haadcode force-pushed the tests/pubsub branch 2 times, most recently from 0a221fc to c9b9751 Compare December 5, 2016 13:53
@haadcode haadcode self-assigned this Dec 5, 2016
@daviddias daviddias changed the title feature: Add Pubsub Tests feature: add pubsub (tests and API Spec) Dec 6, 2016
@daviddias daviddias self-assigned this Dec 9, 2016
Copy link
Contributor

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haadcode I believe I don't understand correctly the purpose of pubsub.peers, could you clarify/fix the docs please?

expect(err.toString()).to.equal(`Error: Not subscribed to '${topic}'`)
done()
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haadcode why would it fail if I'm not subscribed to a topic? Could you clarify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My logic here was that the state of the subscriptions is the source of truth: if you're subscribed, you can query it, cancel it, etc. If you're not, you can't.

What would you expect to receive if you're not subscribed to the topic and call .peers()? En empty list?

Say we have a use case like in the tests for the "waitForPeers", we callback only after we received peers. We don't subscribe to the topic but we keep polling pubsub.peers in the hopes that it returns the peer some day. We keep waiting and waiting and it doesn't seem to work, we check connectivity, we start looking elsewhere, because peers just returns an empty array. That's pretty confusing behaviour for the API. In this case, I believe it's better to tell the user with an error that "hey, what' you're maybe trying to do, will not work".

Copy link
Contributor

@daviddias daviddias Dec 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you expect to receive if you're not subscribed to the topic and call .peers()? En empty list?

For me peers(topic) tells me I should expect "give me the peers I have in my peerSet that are subscribed to a given topic".

@haadcode
Copy link
Contributor Author

I'm ok merging this when you are.

Copy link
Contributor

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haadcode found problems running the new enabled tests in js-ipfs-api.

Also, the process.stdout.write won't fly in the browser, right now I'm commenting them out, but it is preferable to find an alternative logging.

@@ -143,7 +154,7 @@ module.exports = (common) => {
})
})

it.skip('returns no peers within 10 seconds', (done) => {
it('returns no peers within 10 seconds', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haadcode this test is failing in js-ipfs-api

@@ -159,7 +170,7 @@ module.exports = (common) => {
})
})

it.skip('doesn\'t return extra peers', (done) => {
it('doesn\'t return extra peers', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haadcode this one too

@@ -182,10 +193,16 @@ module.exports = (common) => {
})
})

it.skip('returns peers for a topic - one peer', (done) => {
it('returns peers for a topic - one peer', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haadcode and this one

@@ -182,10 +193,16 @@ module.exports = (common) => {
})
})

it.skip('returns peers for a topic - one peer', (done) => {
it('returns peers for a topic - one peer', (done) => {
// Currently go-ipfs returns peers that have not been subscribed to the topic
// Enable when go-ipfs has been fixed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not filter at js-ipfs-api?

@daviddias
Copy link
Contributor

I'm ok merging this when you are.

Found some issues when running the new tests you added/enabled in js-ipfs-api. They run well in js-ipfs though.

@haadcode
Copy link
Contributor Author

haadcode commented Dec 12, 2016

Found some issues when running the new tests you added/enabled in js-ipfs-api. They run well in js-ipfs though.

@diasdavid this is due to using a (old) version go-ipfs that has bugs for those tests. As far as I know they're now fixed in master but we need to wait for go-ipfs 0.4.5-rc1 release to verify the tests are working.

~~Shall we put this to "blocked" until we have that?~~~

We don't need to put this on hold, but note that when running these tests with js-ipfs-api, one needs to use go-ipfs 0.4.5 binary built from git (master).

outputProgress()
ipfs2.pubsub.publish(topic, expectedString, (err) => {
expect(err).to.not.exist
process.nextTick(() => loop())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haadcode this is till Node.js specific

- `options` - type: Object, optional, might contain the following properties:
- `discover`: type: Boolean - Will use the DHT to find

`callback` must follow `function (err, subscription) {}` where Subscription is a Node.js Stream in Object mode, emiting a `data` event for each new message on the subscribed topic.`err` is an error if the operation was not successful.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good interface. We all know the issues of node.js streams and using object streams is even more problematic, as some modules (like hapi.js) don't even work with object streams.

I would propose a simpler api using raw EventEmitter.

const handler = onMessage
ipfs.pubsub.subscribe('mytopic', {discover: true}, onMessage)
ipfs.pubsub.unsubscribe('mytopic', onMessage)

Which would be implemented using EventEmitter and mostly aliases for .on and removeListener. Where removeListener does a check onto emitter.listenerCount(topic) and if that is 0 it will actually unsubscribe from the underlying thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can implement this, but would like some feedback from @haadcode and @gavinmcdermott before :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require changes in the js-ipfs-api PR too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. Let's do it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Please reuse open connections in js-ipfs-api, i.e: If a subscription request is already open, avoid opening a new one, just increase the ref count.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dignifiedquire - Awesome. Let me know if there's any areas you need help / support in this!

`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.

If no `callback` is passed, a [promise][] is returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docs on the value that is resolved


- `topic` - type: String

`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docs on the value that is resolved


### Features

* **object:** add template option to object.new ([2f23617](https://github.com/ipfs/interface-ipfs-core/commit/2f23617))
Copy link
Contributor

@dignifiedquire dignifiedquire Dec 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a changelog in a pr?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that is from a rebase

@@ -41,6 +41,19 @@ module.exports = (common) => {
done()
})
})

it.skip('template unixfs-dir', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems entirely unrelated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as #101 (comment)

const topics = ['one', 'two', 'three']
series(
topics.map((t) => (cb) => ipfs1.pubsub.subscribe(t, cb))
, (err, subs) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put the comma at the end of the line

@@ -156,7 +157,8 @@ module.exports = (common) => {
})
})

it('returns no peers within 10 seconds', (done) => {
// I don't understand the purpose of this test
it.skip('returns no peers within 10 seconds', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})

describe('.peers', () => {
it('returns an error when not subscribed to a topic', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an open question in this interface. I personally don't understand why the question "Tell me who I know that is subscribed to a topic" needs to fail in case I'm not interested to the topic.

@haadcode could you clarify your argument for it to be this way?

@gavinmcdermott @dignifiedquire thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not throwing

Copy link

@gavinmcdermott gavinmcdermott Dec 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a consumer, I'd be a little surprised to encounter a failure case when asking for a list of the peers subscribed to a topic. Here's the rational behind this for me:

  • When I'm making this call, I feel like I'm in the mode of asking the following: "Will you please give me a list of all the people I know who are subscribed to this topic?"
  • To me, the above question feels disconnected from any notion of my subscriptions

I'm not set on this by any means; this is just my mental model.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm absolutely fine not throwing an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a way to look at it as "closed" channels. Kinda like, if you don't participate, you're not allowed to know. But I think this can be achieved with topic CIDs at a later point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, will change to not throwing behaviour


it.skip("doesn't return extra peers", (done) => {
// Currently go-ipfs returns peers that have not been
// subscribed to the topic. Enable when go-ipfs has been fixed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this means is that js-ipfs-api should filter out those who aren't subscribed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how js-ipfs-api could do that if go doesn't return tge right values. The api only knows about local subs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, fair point :( Is there a feature request for the go-ipfs implementation? @whyrusleeping @Kubuxu ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was resolved recently, can you give it another try?

Copy link
Contributor

@dignifiedquire dignifiedquire Dec 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fixed in master, but not the build we can pull in

], (err) => {
expect(err).to.not.exist
setTimeout(() => {
ipfs1.pubsub.peers(topic, (err, peers) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these peers, peerInfo objects?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are peer ids encoded as b58 multihash

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so strings

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be awesome to have a way to fetch peer info from the http api, namely known multiaddrs, public key, supported transports, etc //cc @whyrusleeping

function sub1 (msg) {
inbox1.push(msg.data.toString())
// TODO: enable when go-ipfs is unbroken
// expect(msg.from).to.be.eql(ipfs2.peerId.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a issue that can also be linked here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's mentioned in the first case, I just didn't want to duplicated it all over the file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.

If no `callback` is passed, a [promise][] is returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please complete

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


- `topic` - type: String

`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please complete

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@dignifiedquire
Copy link
Contributor

Ready for next review


##### `Go` **WIP**

##### `JavaScript` - ipfs.pubsub.publish(topic, data, callback)

- `topic` - type: String
- `data` - type: Buffer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intentionally remove the data argument?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

##### `JavaScript` - ipfs.pubsub.publish(topic, data, callback)

- `topic: string`
- `callback: (Error) => ()` - Calls back with an error or nothing if the publish was successfull.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is missing the description of data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛎

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

describe('.publish', () => {
it('message from string', (done) => {
ipfs1.pubsub.publish(topic, 'hello friend', done)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried with accepting plain strings as argument. The issue that we had last week Monday was because the initial pubsub code @haadcode wrote would always convert any value to a Buffer on the publish implementation, but then, because the tests were written like expect(dataReceived).to.equal('some string'), the implementation had a data.toString() internally as a quick patch, and when I changed that to make it an operation in the outside (like we have here now, see below, preserving the buffer type), it made orbit stop working because there was an assumption that 'data' was a string, since orbit publishes strings (or was publishing).

Strings and Buffers are one of banes of JavaScript, it would be better to force it to be just Buffer and no other type (creating a test here to make sure it fails with anything non buffer), to avoid future problems.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also check strictly for string or Buffer, but nothing else, which makes it a bit nicer on the user, but avoids issues like passing an array by accident.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the case I present was exactly because of a user expecting if it published a 'string', it would come out a 'string'.

But yeah, at least, restrict everything else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which makes it a bit nicer on the user

The other option would be to have a big bold note "Any string will be converted to a Buffer"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • needs to be resolved before the merge

Copy link
Contributor Author

@haadcode haadcode Dec 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree @diasdavid that this is something we should decide now as it has bitten us already in a bad way. What do we do in other function that accept similar data as a param, like object.put? It might be a good idea to follow similar convention. If it's string+buffer, then what David proposes makes sense (always convert to buffer and make it as explicit to the user as possible (docs + erroring on anything but string or buffer). If it's only a buffer, it would also make sense to me (input buffer, receive buffer). This is how I tried to approach it in js-ipfs-api: everything we receive is a string, so inputs should be strings (from user's perspective). Obviously we would need to change js-ipfs-api to convert all strings to buffers, and probably in a lot of use cases the user then converts the buffer back to a string, but I suppose it's a cost we could live with (and on a positive side, js-ipfs would be tiny bit faster because it only needs to use buffers).

So... I think I like the idea of accepting buffers-only the most, but it wouldn't be too bad if we accepted strings too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, going to change things to buffer only then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor things, the String vs Buffer needs a resolution, otherwise LGTM 👍


- `topic: string`
- `options: Object` - (Optional), might contain the following properties:
- `discover`: type: Boolean - Will use the DHT to find
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to find.." - sentence needs to be finished

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great sentence :P

##### `JavaScript` - ipfs.pubsub.publish(topic, data, callback)

- `topic: string`
- `callback: (Error) => ()` - Calls back with an error or nothing if the publish was successfull.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛎

- `topic: string`
- `callback: (Error) => ()` - Calls back with an error or nothing if the publish was successfull.

- Returns: `Promise` if no `callback` was passed otherwise `undefined`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have used always: If no callback is passed, a [promise][] is returned., I'm fine changing the sentence, but I do like consistency :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed back

@@ -42,7 +42,7 @@ module.exports = (common) => {
})
})

it('template unixfs-dir', (done) => {
it.skip('template unixfs-dir', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to skip this one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't even know why this is here in the first place

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

done()
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use the chai checkmark thing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly found this to be simpler to use and understand. But not opposed to switching.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good :)

describe('.publish', () => {
it('message from string', (done) => {
ipfs1.pubsub.publish(topic, 'hello friend', done)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • needs to be resolved before the merge

const handler2 = (msg) => {
expect(msg.data.toString()).to.be.eql('hello')
check()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been kind of declaring functions always with the word function, it has some benefits as making it easy to grep. We kind of have followed (naturally) the pattern of always using function throughout the code and I would like to keep it consistent, unless there is a strong case not to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have used function I try to use const name = () especially inside other functions and to avoid using functions before they are declared, as it is very unfortunate that function declarations are hoisted to the top level, allowing for code to use functions before they have been declared.

return done(err)
}
// give some time to let everything connect
setTimeout(done, 300)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be here? Will it fail it it doesn't?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes

@daviddias daviddias merged commit 99a6bc4 into master Dec 21, 2016
@daviddias daviddias deleted the tests/pubsub branch December 21, 2016 15:21
@dignifiedquire
Copy link
Contributor

🎉 100 comments

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants